package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA
 *
 * @Auther: 宋港迎
 * @Date: 2020/08/21/13:50
 * @Destription:
 */
@Getter
public enum XbbSetUpdateRuleEnum {

    /**
     * 关联业务
     */
    ASSOCIATED_BUSINESS(3, "enum.XbbSetUpdateRuleEnum.name.associated_business", "associatedBusiness"),

    /**
     *通话记录
     */
    CALL_LOG(1, "enum.XbbSetUpdateRuleEnum.name.call_log", "callLog"),

    /**
     * 客户阶段
     */
    CUSTOMER_STAGE_LIST(2, "enum.XbbSetUpdateRuleEnum.name.customer_stage_list", "customerStageList"),

    CLUE_STAGE_LIST(4, "enum.XbbSetUpdateRuleEnum.name.clue_stage_list", "clueStageList"),

    UNKNOWN(404,"enum.XbbSetUpdateRuleEnum.name.unknown","unknown");

    /**
     * 枚举值
     */
    private final int code;
    /**
     * 枚举信息--中文名称
     */
    private final String name;
    /**
     * 枚举类型--英文名称
     */
    private final String alias;

    XbbSetUpdateRuleEnum(Integer code, String name, String alias){
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return XbbRefTypeEnum
     */
    public static XbbSetUpdateRuleEnum getByCode(Integer code) {
        for (XbbSetUpdateRuleEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }


    /**
     * 获取全部枚举
     *
     * @return List<XbbRefTypeEnum>
     */
    public List<XbbSetUpdateRuleEnum> getAllEnum() {
        List<XbbSetUpdateRuleEnum> list = new ArrayList<>();
        for (XbbSetUpdateRuleEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (XbbSetUpdateRuleEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getI18nName() {
        return name;
    }

}
